<template>
  <div class="dish-item-modern">
    <div class="dish-image-container">
      <el-image
          :src="cptp + dish.cptp"
          alt="菜品图片"
          class="dish-image"
          fit="cover"
          lazy>
        <template #placeholder>
          <div class="image-placeholder">
            <el-icon><Picture /></el-icon>
          </div>
        </template>
        <template #error>
          <div class="image-error">
            <el-icon><Picture /></el-icon>
          </div>
        </template>
      </el-image>
      <div v-if="dish.tag" class="dish-tag">{{ dish.tag }}</div>
    </div>
    <div class="dish-info">
      <h4 class="dish-name">{{ dish.cpmc }}</h4>
      <p class="dish-description" v-if="dish.cpms">{{ dish.cpms }}</p>
      <div class="dish-price-container">
        <span class="dish-price">¥{{ dish.cpjg }}</span>
        <span v-if="dish.originalPrice" class="dish-original-price">¥{{ dish.originalPrice }}</span>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { Picture } from '@element-plus/icons-vue'

defineProps({
  dish: {
    type: Object,
    required: true
  }
})

const cptp = '/api/upload/'
</script>

<style scoped>
.dish-item-modern {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.dish-item-modern:hover {
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.1);
  transform: translateY(-2px);
}

.dish-image-container {
  position: relative;
  height: 120px;
  overflow: hidden;
}

.dish-image {
  width: 100%;
  height: 100%;
  transition: transform 0.3s ease;
}

.dish-image-container:hover .dish-image {
  transform: scale(1.05);
}

.image-placeholder,
.image-error {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  color: #999;
}

.image-placeholder i,
.image-error i {
  font-size: 1.5rem;
}

.dish-tag {
  position: absolute;
  top: 8px;
  left: 8px;
  background-color: #ff4d4f;
  color: white;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 4px;
  font-weight: 500;
}

.dish-info {
  padding: 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.dish-name {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
  color: #333;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dish-description {
  font-size: 0.8rem;
  color: #666;
  margin: 0;
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.dish-price-container {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 5px;
}

.dish-price {
  font-size: 1.1rem;
  color: #ff6b35;
  font-weight: 700;
}

.dish-original-price {
  font-size: 0.9rem;
  color: #999;
  text-decoration: line-through;
}
</style>
